DEBUG = y

# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DDEBUG
else
  DEBFLAGS = -O3 -DNDEBUG
endif

OBJ_NAME := park_agent park_prober
#OUT_DIR = ./output/
CROSS_COMPILE =  arm-linux-uclibcgnueabi-
TFTP_BOOT := ~/exchange/parking/tftpboot

CC = $(CROSS_COMPILE)gcc
RANLIB = $(CROSS_COMPILE)ranlib
AR = $(CROSS_COMPILE)ar


# show the path to compiler, where to find header files and libraries
#INCFLAGS = -I /home/developer/arm926t_fpu_443/output/staging/usr/arm-linux-uclibcgnueabi/include -L /home/developer/arm926t_fpu_443/output/staging/usr/arm-linux-uclibcgnueabi/lib
INCLUDEPATH := -I /home/developer/arm926t_fpu_443/output/staging/usr/arm-linux-uclibcgnueabi/include -I./mxml
LIBPATH := -L /home/developer/arm926t_fpu_443/output/staging/usr/arm-linux-uclibcgnueabi/lib -L./mxml 
#MXML := -I./mxml -L./mxml -lmxml           
# compiler switches
CFLAGS  := -DREAL_IS_FIXED -DLINUX -DTERM_CONTROL \
			-DOSS -Wall -O6  \
			-fomit-frame-pointer -funroll-all-loops \
			-finline-functions -ffast-math $(DEBFLAGS) -march=armv5te -mtune=arm9tdmi -mabi=aapcs-linux

#CFLAGS := -g -O2 -D_REENTRANT -Wall -L ./lib -I ./lib


LIBS := -lpthread -lmxml

CLEANFILES := *.o

SOURCE := $(wildcard *.c)
OBJS := $(patsubst %.c,%.o,$(SOURCE))

%.o:%.c 
	$(CC) -c -o $@ $< $(CFLAGS) $(LIBS) $(INCLUDEPATH) $(LIBPATH)

.PHONY:all
all: $(OBJ_NAME)

#$(OBJ_NAME):$(OBJS)
#	$(CC) -o $@  $^ $(LIBS) $(CFLAGS) $(INCLUDEPATH) $(LIBPATH) 

park_prober: io.o stty.o prober_dev.o public.o NetEngine.o tpool.o SmartBuffer.o dc_dev_ctl.h uthash.h
	$(CC) -o $@  $^ $(LIBS) $(CFLAGS) $(INCLUDEPATH) $(LIBPATH)

park_agent: public.o SmartBuffer.o park_led.o park_commu.o tpool.o park_prober_commu.o NetEngine.o park_dev_unit.o uthash.h list.h includes.h
	$(CC) -o $@  $^ $(LIBS) $(CFLAGS) $(INCLUDEPATH) $(LIBPATH) $(MXML)

install:
	@if [ -e $(TFTP_BOOT) ] ;\
	 then echo "$(TFTP_BOOT) exists - good." ;\
        else mkdir -p $(TFTP_BOOT);\
        fi;	
	cp $(OBJ_NAME) $(TFTP_BOOT)
	
clean:
	rm -f $(CLEANFILES) $(OBJ_NAME)

